package com.physique.tea.Mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.physique.tea.Pojo.Physique;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface PhysiqueMapper extends BaseMapper<Physique> {
    // 增
    @Insert("INSERT INTO PHYSIQUE (ID, PHYNAME, FEATURES, RISK) VALUES (#{ID}, #{PHYNAME}, #{FEATURES}, #{RISK})")
    @Options(useGeneratedKeys = true, keyProperty = "ID")
    int insertPhysique(Physique physique);

    // 删
    @Delete("DELETE FROM PHYSIQUE WHERE ID = #{ID}")
    int deleteById(@Param("ID") Integer ID);

    // 改
    @Update("UPDATE PHYSIQUE SET PHYNAME = #{PHYNAME}, FEATURES = #{FEATURES}, RISK = #{RISK} WHERE ID = #{ID}")
    int updatePhysique(Physique physique);

    // 查
    @Select("SELECT ID, PHYNAME, FEATURES, RISK FROM PHYSIQUE WHERE ID = #{ID}")
    Physique selectById(@Param("ID") Integer ID);

    @Select("SELECT ID, PHYNAME, FEATURES, RISK FROM PHYSIQUE WHERE PHYNAME = #{PHYNAME}")
    Physique selectByPhyname(@Param("PHYNAME") String PHYNAME);

    @Select("SELECT ID, PHYNAME, FEATURES, RISK FROM PHYSIQUE WHERE PHYNAME LIKE '%' || #{NAME} || '%'")
    List<Physique> searchByName(@Param("NAME") String NAME);

    @Select("SELECT ID, PHYNAME, FEATURES, RISK FROM PHYSIQUE")
    List<Physique> selectAll();

    @Select("SELECT PHYNAME, LENGTH(FEATURES) AS FEATURE_LENGTH FROM PHYSIQUE ORDER BY FEATURE_LENGTH DESC")
    List<Map<String, Object>> selectByFeatureLength();
}